<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#-- 包含其他文件的内容 -->
    <#include "../common/header.ftl"/>
    <script type="text/javascript" src="/js/ckeditor/ckeditor.js"></script>

        <script>
            $(function () {

                $('.inputBtn').click(function () {
                    $('#editForm')[0].reset();//reset不能清空type为hidden的隐藏域,如果type=text,有hidden属性则可以被清空
                    $('#coverImg').attr('src','');
                    var json = $(this).data('json');
                    if (json){
                        // console.log(json);
                        $('input[name=id]').val(json.id);
                        $('input[name=grogshopName]').val(json.grogshopName);
                        $('#coverImg').attr('src',json.coverUrl);
                        $('input[name=coverUrl]').val(json.coverUrl);
                        $('input[name=price]').val(json.price);
                        $('input[name=site]').val(json.site);
                        $('input[name=grade]').val(json.grade);
                        /* $('select[name="place.id"]').val(json.placeId);*/
                        $('select[name=state]').val(json.state);

                    }
                    $('#inputModal').modal('show');
                });

                $(".submitBtn").click(function () {
                      $('#editForm').ajaxSubmit(function (data) {
                            handleResult(data);
                      })
                })


                //修改客户状态(回显)
                $(".statusBtn").click(function () {
                    //获取当前按钮中data-json的值
                    var json = $(this).data("json");
                    if (json) {
                        $("#statusForm input[name='id']").val(json.id)
                        $("#statusForm input[name='state']").val(json.state)
                    }
                    $("#statusModal").modal("show");
                })
                //绑定提交
                $(".statusSubmitBtn").click(function () {
                    $("#statusForm").ajaxSubmit(function () {
                        reload()
                    });
                })
            })
        </script>

</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <#-- 往数据模型中填充一个属性 -->
            <#assign menu="orderForm"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">酒店订单管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/orderForm/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword"
                           value="${(qo.keyword)!}" placeholder="请输入标题">
                </div>
                <button id="btn_query" class="btn btn-success">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
               <#-- <a role="button" class="btn btn-success inputBtn">
                    <span class="glyphicon glyphicon-plus"></span> 添加
                </a>-->
            </form>

            <table class="table table-striped table-hover" >
                <tr>
                    <th>编号</th>
                    <th>客户姓名</th>
                    <th>电话</th>
                    <th>身份证号</th>
                    <th>入住时间</th>
                    <th>离开时间</th>
                    <th>金额</th>
                    <th>酒店名</th>
                    <th>状态</th>
                </tr>

            <#-- 循环迭代指令 -->
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index+1}</td>
                        <td>${entity.name}</td>
                        <td>${entity.phone}</td>
                        <td>${entity.numberID}</td>
                        <td>${(entity.checkInTime?string("yyyy-MM-dd HH:mm:ss"))!}</td>
                        <td>${(entity.leaveTime?string("yyyy-MM-dd HH:mm:ss"))!}</td>
                        <td>${(entity.money)!}</td>
                        <td>${(entity.grogshop.grogshopName)!}</td>
                        <td>${entity.stateString}</td>
                        <td>
                            <#--<a class="btn btn-info btn-xs inputBtn" data-json='${(entity.json)!}' >
                                <span class="glyphicon glyphicon-pencil"></span> 编辑
                            </a>-->
                            <a class="btn btn-info btn-xs statusBtn" data-json='${(entity.json)!}' >
                                <span class="glyphicon glyphicon-pencil"></span> 修改状态
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>


<!-- 模态框必须作为body的子标签 -->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/orderForm/saveOrUpdate.do" method="post" id="editForm">
                   <input type="text" name="id" hidden>&ndash;&gt;
                    <input type="hidden" name="id" >
                    <div class="form-group" >
                        <label class="col-sm-4 control-label">客户姓名：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name" >
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">电话：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="phone" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">身份证号：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="numberID" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">入住时间：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="checkInTime" >
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">离开时间：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="leaveTime" >
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">金额：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="money" >
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    <span class="glyphicon glyphicon-off"></span> 关闭
                </button>
                <button type="button" class="btn btn-primary submitBtn">
                    <span class="glyphicon glyphicon-saved"></span> 保存
                </button>
            </div>
        </div>
    </div>
</div>

<#-- 修改客户状态 -->
<div class="modal fade" id="statusModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">

        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">修改客户状态</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/orderForm/updateStatus.do" method="post" id="statusForm">
                    <input type="hidden" name="id" />
                    <div class="form-group">
                        <label class="col-lg-4 control-label">客户状态：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="state">
                                <option value="-1">没有入住</option>
                                <option value="0">拒绝</option>
                                <option value="1">待审核</option>
                                <option value="2">审核通过</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary statusSubmitBtn">保存</button>
            </div>
        </div>
    </div>
</div>

</body>
</html>